package com.mobile.driver.controls {
   import mx.collections.ArrayCollection;

   [Bindable]
   public class DataCache {
      private static var _instance:DataCache = null;
      public static function getInstance():DataCache {
         if (!_instance) {
            _instance = new DataCache();
         }
         return _instance;
      }
      
      public function DataCache() {
         if (_instance) {
            throw new Error('DataCache is singleton');
         }
      }
      
      public var airPortList:ArrayCollection = new ArrayCollection([
         {name:"虹桥机场2号航站楼", code:"hongqiao2"},
         {name:"浦东国际机场", code:"pudonginternational"}]);
      
      public var stationList:ArrayCollection = new ArrayCollection([
         {name:"虹桥火车站", code:"hongqiaostation"},
         {name:"上海火车站", code:"shanghaistation"},
         {name:"上海南站", code:"shanghaisouthstation"},
         {name:"上海西站", code:"shanghaiweststation"}]);
      
      public function getAirPortNameByCode(code:String):String {
         return getDictNameByCode(airPortList, code);
      }
      
      public function getStationNameByCode(code:String):String {
         return getDictNameByCode(stationList, code);
      }
      
      public function getDictByCode(dicts:ArrayCollection, code:String):* {
         for each (var dict:* in dicts) {
            if (dict.code == code) {
               return dict
            }
         }
         return null;
      }
      
      public function getDictNameByCode(dicts:ArrayCollection, code:String):String {
         for each (var dict:* in dicts) {
            if (dict.code == code) {
               return dict.name
            }
         }
         return "";
      }
   }
}